package net.sparrow.module;

import org.lwjgl.opengl.GL11;

import net.minecraft.src.EntityClientPlayerMP;
import net.minecraft.src.EnumAction;
import net.minecraft.src.Packet12PlayerLook;
import net.sparrow.Sparrow;
import net.sparrow.cmd.CommandHandler;
import net.sparrow.event.DataField;
import net.sparrow.event.SpEventListener;
import net.sparrow.event.SpTickEvent;
import net.sparrow.util.Util;

public class FastConsumeModule extends Module{

	@DataField( id="player.fastconsume")
	public Boolean enabled = false;
	
	//TODO configure delay time?
	private int tickTimer = 0;
	private static final int DELAYTIME = 35;
	private long lastTime = 0;
	
	@SpEventListener
	public void onFrame(SpTickEvent e) {
		if(!Util.inGame()) {
			return;
		}
		EntityClientPlayerMP player = Sparrow.mc().player();
		if (player.getItemInUse() == null || !enabled) {
			return;
		}
		// if the item can be eaten/drank
		if (player.getItemInUse().getItemUseAction() == EnumAction.eat ||  player.getItemInUse().getItemUseAction() == EnumAction.drink) {
			if (player.isUsingItem() && player.onGround && System.currentTimeMillis() - lastTime > DELAYTIME) {
			// and its being used
				Util.sendPacket(
						new Packet12PlayerLook
						(player.rotationYaw, 
								player.rotationPitch, 
								player.onGround));
				lastTime = System.currentTimeMillis();
				GL11.glColor3f(0f,0f,0f);
			}
		}
	}
	
	
	public CommandHandler loadCommands() {
		return new CommandHandler().withDefaultToggle("player.fastconsume");
	}
}
